package com.coffee.soft.service.impl;

import com.coffee.soft.entity.Items;
import com.coffee.soft.entity.ItemsShow;
import com.coffee.soft.mapper.ItemsMapper;
import com.coffee.soft.service.ItemsEatDrinkDiy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Stack;

/**
 * @Author:LiuRuidong
 * @Description:
 * @Date: Created in 19:14 2018/2/4
 * @Modified By:
 */
@Service
public class ItemsEatDrinkDiyImpl implements ItemsEatDrinkDiy {
    @Autowired
    private ItemsMapper itemsMapper;

    /**
     * @Author：LiuRuidong
     * @Description: 吃的东西
     * @Date:2018/2/5 1:32
     * @Param:
     * @return
     */
    @Override
    public List<ItemsShow> eatItems(String itemsId) {
        int i =0 ;
//       存储要展示的东西
        List<ItemsShow> itemsShowList = new ArrayList();
//查询出来的所有吃的
        List<Items> itemsList = itemsMapper.selectEat();
//迭代吃的
        Iterator<Items> iterator = itemsList.iterator();
        ItemsShow itemsShow = null;
        while(iterator.hasNext()){
            Items items = iterator.next();
            if(items.getItemsId().equals(itemsId)){
                for(;i<4;i++) {
                    itemsShow = new ItemsShow();
                    itemsShow.setItemsId(items.getItemsId());
                    itemsShow.setItemsName(items.getItemsName());
                    itemsShow.setItemsDiscountPrice(items.getItemsPrice()*items.getItemsDiscount());
                    itemsShow.setItemsPicture(items.getItemsPicture());
                    itemsShowList.add(itemsShow);
                    if(iterator.hasNext()){
                        items = iterator.next();
                    }else{
                        iterator = itemsList.iterator();
                    }
                }
            }
        }

        return itemsShowList;
    }
/**
 * @Author：LiuRuidong
 * @Description: 喝的东西
 * @Date:2018/2/5 1:32
 * @Param:
 * @return
 */
    @Override
    public List<ItemsShow> drinkItems(String itemsId) {
            int i =0 ;
    //       存储要展示的东西
            List<ItemsShow> itemsShowList = new ArrayList();
    //查询出来的所有喝的
            List<Items> itemsList = itemsMapper.selectDrink();
    //迭代喝的
            Iterator<Items> iterator = itemsList.iterator();
            ItemsShow itemsShow = null;
            while(iterator.hasNext()){
                Items items = iterator.next();
                if(items.getItemsId().equals(itemsId)){
                    for(;i<4;i++) {
                        itemsShow = new ItemsShow();
                        itemsShow.setItemsId(items.getItemsId());
                        itemsShow.setItemsName(items.getItemsName());
                        itemsShow.setItemsDiscountPrice(items.getItemsPrice()*items.getItemsDiscount());
                        itemsShow.setItemsPicture(items.getItemsPicture());
                        itemsShowList.add(itemsShow);
                        if(iterator.hasNext()){
                            items = iterator.next();
                        }else{
                            iterator = itemsList.iterator();
                        }
                    }
                }
            }

            return itemsShowList;
    }
/**
 * @Author：LiuRuidong
 * @Description: diy东西
 * @Date:2018/2/5 1:33
 * @Param:
 * @return
 */
    @Override
    public List<ItemsShow> diyItems(String itemsId) {
            int i =0 ;
    //       存储要展示的东西
            List<ItemsShow> itemsShowList = new ArrayList();
    //查询出来的所有所有的
            List<Items> itemsList = itemsMapper.selectAll();
    //迭代DIY的
            Iterator<Items> iterator = itemsList.iterator();
            ItemsShow itemsShow = null;
            while(iterator.hasNext()){
                Items items = iterator.next();
                if(items.getItemsId().equals(itemsId)){
                    for(;i<4;i++) {
                        itemsShow = new ItemsShow();
                        itemsShow.setItemsId(items.getItemsId());
                        itemsShow.setItemsName(items.getItemsName());
                        itemsShow.setItemsDiscountPrice(items.getItemsPrice()*items.getItemsDiscount());
                        itemsShow.setItemsPicture(items.getItemsPicture());
                        itemsShowList.add(itemsShow);
                        if(iterator.hasNext()){
                            items = iterator.next();
                        }else{
                            iterator = itemsList.iterator();
                        }
                    }
                }
            }

            return itemsShowList;
    }
}
